/**
 * Description:
 * Class Name:Java9Collection
 * Date:2022/3/14 16:34
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第8章_Java集合._8_8_操作集合的工具类_Collections._8_8_5_Java9新增的不可变集合;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class Java9Collection {
    public static void main(String[] args) {
        // 创建4个不可变集合
        var set = Set.of("Java", "Kotlin", "Go", "Swift");
        var list = List.of(32, -25, 666, 231);
        var map = Map.of("语文", 89, "数学", 82, "英语", 92);
        // 使用Map.Entry()方法显式构建key-value对
        var map2 = Map.ofEntries(
                Map.entry("语文", 89),
                Map.entry("数学", 82),
                Map.entry("英语", 92)
        );

        System.out.println(set);
        System.out.println(list);
        System.out.println(map);
        System.out.println(map2);

        // 修改的话，会引发UnsupportedOperationException异常
        set.add("Ruby");
        list.remove(-25);
        map.remove("语文");
    }
}
